package ext.tianma.part.RawMaterial.datautility;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import wt.log4j.LogR;
import wt.util.WTException;

import com.ptc.core.components.descriptor.ModelContext;
import com.ptc.core.components.factory.AbstractDataUtility;
import com.ptc.core.components.factory.dataUtilities.AttributeDataUtilityHelper;
import com.ptc.core.components.rendering.GuiComponent;
import com.ptc.core.components.rendering.guicomponents.GUIComponentArray;
import com.ptc.core.components.rendering.guicomponents.IconComponent;
import com.ptc.core.components.rendering.guicomponents.TextArea;
import com.ptc.core.components.rendering.guicomponents.TextBox;
import com.ptc.core.ui.resources.ComponentMode;

import ext.tianma.doc.SendOut.datautilities.PickerUtil;
import ext.tianma.doc.SendOut.datautilities.SupplierDataUtility;

/**
 * 类名: MaterialTypeUtility </br>
 * 包名: ext.tianma.part.RawMaterial.Utility
 * 描述: 原材料的材料型号搜索
 * @author xucr
 * 创建时间: 2020年8月4日
 * 发布版本: V1.0
 */
public class MaterialTypeUtility extends AbstractDataUtility{
	
	private static final String	CLASSNAME	= SupplierDataUtility.class.getName();

	private static final Logger	log			= LogR.getLogger( CLASSNAME );

	public Object getDataValue(String component_id, Object datum, ModelContext mc) throws WTException {
		log.debug( "Enter In getDataValue..." );
		
		ComponentMode descriptorMode = mc.getDescriptorMode();
		if (ComponentMode.CREATE.equals( descriptorMode ) || ComponentMode.EDIT.equals( descriptorMode ) || ComponentMode.VIEW.equals( descriptorMode )) {
			return createPickerComponent( component_id, datum, mc );
		}
		return "";
	}

	public Object createPickerComponent(String component_id, Object datum, ModelContext mc) throws WTException {
		log.debug( "Enter In createPickerComponent..." );
		List<GuiComponent> components = new ArrayList<GuiComponent>();
		
		//文本框
		TextBox suggestTextBox = new TextBox();
		suggestTextBox.setId(component_id);
		suggestTextBox.setWidth(60);
		suggestTextBox.setEnabled(true);
		suggestTextBox.setEditable(true);
		suggestTextBox.setReadOnly(true);
		suggestTextBox.setColumnName(AttributeDataUtilityHelper.getColumnName(component_id, datum, mc));
		
		String jsAction = "javascript:window.open('/Windchill/netmarkets/jsp/part/RawMaterial/searchRawMaterial.jsp"
				+ "','','resizable=no,scrollbars=yes,menubar=no,toolbar=no,location=no,status=yes,top=100,left=400,right=300,height=600,width=500');";
		
		IconComponent button = PickerUtil.createIconComponent( component_id, "add", jsAction );
		components.add( suggestTextBox );
		components.add( button );//取消则不展示按钮后面的搜索框
		return new GUIComponentArray( components );
	}
}
